﻿package com.toncen.samepms.system.dao;

import java.util.List;

import com.toncen.samepms.basic.action.UserAction;
import com.toncen.samepms.common.AbstractDao;
import com.toncen.samepms.common.IDomain;
import com.toncen.samepms.system.domain.Module;

/**
 * 描述：模块表SYSTEM_MODULE的dao文件
 * 
 * @author tch
 */
public class ModuleDao extends AbstractDao<Module> {

	public ModuleDao() {
	}

	/**
	 * 获取全部模块(排除指定的模块)
	 * 
	 * @param exclude
	 * @return
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public List<Module> getAllModuleExclude(Module exclude) throws Exception {
		return findList("getAllModuleExclude", exclude==null?IDomain.UNSAVED_ID:exclude.getId());
	}
	/**
	 * 获取一级根模块
	 * @param exclude
	 * @return
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public List<Module> getAllRootModule() throws Exception {
		return findList("getAllRootModule", null);
	}
	
	/* (non-Javadoc)
	 * @see com.toncen.samepms.common.AbstractDao#add(com.toncen.samepms.common.AbstractDomain)
	 */
	@Override
	public long add(Module domain) throws Exception {
		UserAction.clearCachePermissions();// 清除缓存
		return super.add(domain);
	}

	/* (non-Javadoc)
	 * @see com.toncen.samepms.common.AbstractDao#delete(long)
	 */
	@Override
	public int delete(long id) throws Exception {
		UserAction.clearCachePermissions();// 清除缓存
		return super.delete(id);
	}

	/* (non-Javadoc)
	 * @see com.toncen.samepms.common.AbstractDao#update(com.toncen.samepms.common.AbstractDomain)
	 */
	@Override
	public int update(Module domain) throws Exception {
		UserAction.clearCachePermissions();// 清除缓存
		return super.update(domain);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.comit.common.db.BaseDao#initialize()
	 */
	@Override
	protected void initialize() {
		setStatementPrefix("Module");
		setStatementDivision(".");
	}
}
